home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-01-01 | 54.9 KB | 1,864 lines | [TEXT/MPS ] |
- /*
- File: DrawObj.cpp
-
- Contains: Object accessor implementation for the AppleTestDraw_DrawPart
-
- Owned by: Caia Grisar
-
- Copyright: © 1993 - 1997 by Apple Computer, Inc., all rights reserved.
-
- Change History (most recent first):
-
- <5> 1/3/97 JP 1607652 OpenDoc OSL leaks resolved direct
- object/subject attribute
- <4> 12/13/96 JP 1611571: Renamed parameter
- <3> 9/23/96 JP 1384958: Added test code for
- ShouldHandleEvent
- <2> .03.1996 NP 1333523: Fixed memory leak in
- HandleGetData.
- <43> 10/10/95 NP 1290945: Memory leaks.
- <42> 25/09/95 NP 1979071: Check results of operator new.
- <41> 9/11/95 JP 1269048 & 1283405: Use ODGetComments
- <40> 9/6/95 eeh 1282767: cleanup
- <39> 9/4/95 TJ Added Includes to Compile with out
- PC-Headers.
- <38> 8/25/95 JP 1262410: Comments part to frame fallout
- <37> 7/27/95 eeh 1204615: handle 'exmn' as container
- <36> 6/30/95 JP Accessor foo
- <35> 6/28/95 eeh 1262143: dispose AEDescs
- <34> 6/26/95 JBS &DMc&TÇ 1242642 BB: Refcounting Fixes.
- <33> 6/20/95 NP 1260389: Fix DrawPart's count proc,
- 1260922: Fix DrawPart's compare proc
- <32> 6/19/95 eeh ????? return errAEEventNotHandled to
- trigger defaults
- <31> 6/13/95 eeh 1250399, 1254943, 1251194: handlers/
- accessors return right codes
- <30> 6/7/95 BM #1252253: ContainerPart doesn't always
- give default event handlers a chance.
- Changed HandleGetData, HandleSetData to
- return proper error (instead of an
- ASSERTM).
- <29> 5/26/95 RR #1251403: Multithreading naming support
- <28> 5/21/95 NP 1248898: GetUserToken, ODDescToAEDesc, etc.
- recipe change.
- <27> 5/18/95 eeh 1250424: added revert event support (dummy)
- <26> 5/3/95 NP 1211084: Remove 5$
- <25> 4/26/95 BM #1243574: added element accessors
- (character from null) and related support
- <24> 4/7/95 eeh 1236842: update on DrawCount
- <23> 3/24/95 eeh 1232264: use ODFrame* rather than ODPart*
- to keep track of parts
- <21> 3/21/95 JP 1192027: Include ODRgstry
- <20> 3/20/95 NP 1225985: Change API of CreateSwapToken.
- <19> 3/13/95 NP 1226003: Remove GetContainingFrame from the
- API. Use GetContextFromToken.
- <18> 3/2/95 eeh 1214783: finish work on lists
- <17> 2/22/95 eeh 1222901: use StandardPartToken
- <16> 2/21/95 eeh 1214783: remove pName case; add WASSERTS
- <15> 2/13/95 eeh 1217393: enable GetPropertyFromPart
- <14> 2/3/95 eeh 1217393: use new ODDesc etc
- <13> 1/27/95 NP 1213948: Fix handlers and accessors.
- <12> 1/25/95 jpa Renamed SOM class to Container [1213318]
- <11> 1/22/95 NP GetUserToken et al signature changed
- because of change to AE types.
- <10> 1/16/95 eeh 1211798: use new method of dealing with
- tokens (GetUserToken etc.)
- <9> 11/15/94 NP 1199847-fixed some object accessors and
- event handlers.
- <8> 10/6/94 JBS 1188214: use refcounted Shape & Transform
- <7> 9/29/94 RA 1189812: Mods for 68K build.
- <6> 9/23/94 NP 1185420. Fixed a few problems, some of
- which I had probably introduced before.
- <5> 9/22/94 JBS 1188214: coordinate bias implementation
- <4> 9/15/94 NP 1186778: Changed token handling code.
- <3> 9/9/94 NP 1185851: implement scripting.
- <2> 9/8/94 NP Backed off of a change until SE is working.
- <1> 8/30/94 NP first checked in
- <11> 5/27/94 jpa Support new exceptions [1165267]
- <10> 4/6/94 JBS 1155477
- <9> 3/28/94 CG 1153547: include ODSessM.h instead of
- ODSessn.h.
- <8> 3/26/94 NP 1153509. Messaging not PowerPC ready.
- <7> 3/26/94 NP 1153053.
- <6> 3/25/94 JA JPA: GetPlatformTransform -> GetQDOffset
- (1153438). JBS: Changed API of
- CreateEmbeddedFrameIterator, CanvasChanged
- (1153056, 1153059).
- <5> 3/25/94 MB Symantec ASLM fixes. #1150864
- <4> 3/25/94 eeh bug #1153053: Changes for PPC nativity
- <3> 3/15/94 MB Changes to support SCpp/ASLM builds,
- #1150864.
- <2> 2/16/94 JA Include new AltPoint.h.
- <21> 2/8/94 JA Added missing #includes.
- <20> 2/8/94 TÇ Throw -> THROW & some code clean up
- <19> 2/7/94 JA Utility.h --> ODUtils.h
- <18> 2/7/94 TÇ fixes to compile with PPC Headers
- <17> 2/2/94 JBS new AddDisplayFrame recipie
- <16> 1/31/94 NP Fixed coercion handler to conform to new
- interface.
- <15> 1/28/94 NP Fixed include statements.
- <14> 1/17/94 NP Removed consts from public API.
- <13> 1/17/94 NP Semantic Events callbacks API changes.
- <12> 1/14/94 NP Removed CreateObjSpecifier (it's already in
- OpenDoc) and fixed some include statements.
- <11> 1/11/94 eeh removed "frame" from objspec vocab; work on
- Move event and bounds property (not done)
- <10> 12/20/93 NP Changed calls to CreateSwapToken.
- <9> 12/17/93 eeh object accessors for frames
- <8> 12/15/93 NP CreatePartToken -> CreateSwapToken.
- <7> 12/9/93 SS Compiler conditional #include
- <6> 12/9/93 eeh implement CreateNewPart,
- CreatePartObjectSpec, and SetNewBounds,
- helpers, and general support for scripting,
- esp the make event
- <5> 12/3/93 TÇ Stop including ODError.h, it is included
- as ErrorDef.h inside Except.h
- <4> 12/1/93 CG bug fix.
- <3> 12/1/93 CG Added CreateNewPart, CreatePartObjectSpec,
- GetPropertyFromPart,GetPartFromPart,
- updated HandleGetData and HandleSetData.
- <2> 11/30/93 JA Rearranged #includes for new "frame"
- constant fix.
- <1> 11/16/93 CG first checked in
- To Do:
- */
-
- #ifndef _ALTPOINT_
- #include "AltPoint.h" /* Use C++ savvy ODPoint and ODRect */
- #endif
-
- #ifndef _ODDESUTL_
- #include <ODDesUtl.h>
- #endif
-
- #ifndef SOM_ODOSLToken_xh
- #include <ODOSLTkn.xh>
- #endif
-
- #ifndef SOM_ODAppleEvent_xh
- #include <ODAplEvt.xh>
- #endif
-
- #ifndef _ORDCOLL_
- #include "OrdColl.h"
- #endif
-
- #ifndef _DRAWOBJ_
- #include "DrawObj.h"
- #endif
-
- #ifndef _DRWSHARED_
- #include "DrwShared.h"
- #endif
-
- #ifndef _PRTPRPAC_
- #include "PrtPrpAc.h"
- #endif
-
- //#ifndef _DFRMITER_
- //#include "DFrmIter.h"
- //#endif
-
- #ifndef SOM_DrawEmbeddedFramesIterator_xh
- #include "DrwEmFrI.xh"
- #endif
-
- #ifndef SOM_ODDraft_xh
- #include "Draft.xh"
- #endif
-
- #ifndef SOM_Module_AppleTestDraw_defined
- #include "DrawPart.xh"
- #endif
-
- #ifndef _EXCEPT_
- #include "Except.h"
- #endif
-
- #ifndef SOM_ODFacet_xh
- #include "Facet.xh"
- #endif
-
- #ifndef SOM_ODFrame_xh
- #include "Frame.xh"
- #endif
-
- #ifndef __LIMITS__
- #include <limits.h>
- #endif
-
- #ifndef SOM_ODNameResolver_xh
- #include "NamRslvr.xh"
- #endif
-
- #ifndef SOM_ODPart_xh
- #include "Part.xh"
- #endif
-
- #ifndef SOM_DrawSI_xh
- #include "DrawSI.xh"
- #endif
-
- #ifndef _ITEXT_
- #include "IText.h"
- #endif
-
- #ifndef _SIHELPER_
- #include "SIHelper.h"
- #endif
-
- #ifndef _ODREGISTRY_
- #include "ODRgstry.xh"
- #endif
-
- #ifndef SOM_ODSession_xh
- #include "ODSessn.xh"
- #endif
-
- #ifndef _SEUTILS_
- #include "SEUtils.h"
- #endif
-
- #ifndef SOM_ODObjectSpec_xh
- #include "ODObjSpc.xh"
- #endif
-
- #ifndef SOM_ODShape_xh
- #include "Shape.xh"
- #endif
-
- #ifndef SOM_ODStorageUnit_xh
- #include "StorageU.xh"
- #endif
-
- #ifndef SOM_ODTransform_xh
- #include "Trnsform.xh"
- #endif
-
- #ifndef SOM_ODMessageInterface_xh
- #include "MssgIntf.xh"
- #endif
-
- #ifndef SOM_ODFrameFacetIterator_xh
- #include "FrFaItr.xh"
- #endif
-
- #ifndef _ODUTILS_
- #include "ODUtils.h"
- #endif
-
- #ifndef __AEOBJECTS__
- #include <AEObjects.h>
- #endif
-
- #ifndef __AEPACKOBJECT__
- #include <AEPackObject.h>
- #endif
-
- #ifndef __AEREGISTRY__
- #include <AERegistry.h>
- #endif
-
- #ifndef __ASREGISTRY__
- #include <ASRegistry.h>
- #endif
-
- #ifndef __TEXTUTILS__
- #include <TextUtils.h>
- #endif
-
- #include <string.h>
-
- #ifndef _PRTELMAC_
- #include "PrtElmAc.h"
- #endif
-
- #ifndef _INFOUTIL_
- #include <InfoUtil.h>
- #endif
-
- #ifndef _ODDEBUG_
- #include "ODDebug.h"
- #endif
-
- #ifndef _BARRAY_
- #include "BArray.h"
- #endif
-
- #pragma segment DrawObj
-
-
- //==============================================================================
- // Function prototypes
- //==============================================================================
-
- static void CreatePartObjectSpec(DescType keyForm, AEDesc* containerObjSpec,
- AEDesc *objectSpec);
- static void MoveFacetTransform(ODFacet* facet, Point* desiredLocation,
- ODPart* part);
- void GetDirectParam(ODSession* session, AppleEvent* message,
- AEDesc* evtDp);
-
-
- #define CONTAINER_ACCESSOR_RETURN_TYPE static pascal ODError
-
- void InstallStaticCallbacks( ODSemanticInterface* semtIntf,
- SIHelper* helper, ODSession* session )
- {
- ODObjectAccessorUPP theAccessorUPP ;
-
- theAccessorUPP = NewODObjectAccessorProc( GetPropertyFromNULL ) ;
- helper->InstallObjectAccessor(cProperty, typeNull, theAccessorUPP,
- (ODSLong)session);
-
- theAccessorUPP = NewODObjectAccessorProc( GetPropertyFromNULL ) ;
- helper->InstallObjectAccessor(cProperty, 'exmn', theAccessorUPP,
- (ODSLong)session);
-
- theAccessorUPP = NewODObjectAccessorProc( GetPartFromNULL ) ;
- helper->InstallObjectAccessor(cPart, typeNull, theAccessorUPP,
- (ODSLong)session);
-
- theAccessorUPP = NewODObjectAccessorProc( GetPartFromNULL ) ;
- helper->InstallObjectAccessor(cPart, 'exmn', theAccessorUPP,
- (ODSLong)session);
-
- theAccessorUPP = NewODObjectAccessorProc( GetPropertyFromPart ) ;
- helper->InstallObjectAccessor(cProperty, cPart, theAccessorUPP,
- (ODSLong)session);
-
- theAccessorUPP = NewODObjectAccessorProc( GetCharFromNULL ) ;
- helper->InstallObjectAccessor(cChar, typeNull, theAccessorUPP,
- (ODSLong)session);
-
- theAccessorUPP = NewODObjectAccessorProc( GetCharFromNULL ) ;
- helper->InstallObjectAccessor(cChar, 'exmn', theAccessorUPP,
- (ODSLong)session);
-
- theAccessorUPP = NewODObjectAccessorProc( GetWildcardFromPart ) ;
- helper->InstallObjectAccessor(typeWildCard, cPart, theAccessorUPP,
- (ODSLong)session);
-
- theAccessorUPP = NewODObjectAccessorProc( GetWildcardFromList ) ;
- helper->InstallObjectAccessor(typeWildCard, typeAEList,
- theAccessorUPP, (ODSLong)session);
-
-
- ODEventHandlerUPP theEventHandlerUPP ;
-
- theEventHandlerUPP = NewODEventHandlerProc( HandleSetData ) ;
- helper->InstallEventHandler(kAECoreSuite, kAESetData,
- theEventHandlerUPP,
- (ODSLong)session);
-
- theEventHandlerUPP = NewODEventHandlerProc( HandleGetData ) ;
- helper->InstallEventHandler(kAECoreSuite, kAEGetData,
- theEventHandlerUPP,
- (ODSLong)session);
-
- theEventHandlerUPP = NewODEventHandlerProc( HandleMeow ) ;
- helper->InstallEventHandler('cats', 'meow',
- theEventHandlerUPP,
- (ODSLong)session);
-
- // <eeh> for testing only!!!!
- theEventHandlerUPP = NewODEventHandlerProc( HandleRevert ) ;
- helper->InstallEventHandler('misc', 'rvrt',
- theEventHandlerUPP,
- (ODSLong)session);
-
- theEventHandlerUPP = NewODEventHandlerProc( HandleCreate ) ;
- helper->InstallEventHandler(kAECoreSuite, kAECreateElement,
- theEventHandlerUPP,
- (ODSLong)session);
-
- theEventHandlerUPP = NewODEventHandlerProc( HandleMove ) ;
- helper->InstallEventHandler(kAECoreSuite, kAEMove, theEventHandlerUPP,
- (ODSLong)session);
-
- ODCoercionHandlerUPP coercionHndUPP =
- NewODDescCoercionHandlerProc( CoerceList2RGB ) ;
- helper->InstallCoercionHandler(typeAEList, cRGBColor,
- coercionHndUPP, (ODSLong)kODNULL, kODTrue);
-
- coercionHndUPP =
- NewODDescCoercionHandlerProc( CoerceDPElemToChar ) ;
- helper->InstallCoercionHandler(typeDPElem, typeChar,
- coercionHndUPP, (ODSLong)kODNULL, kODTrue);
-
- ODCompareUPP compUPP = NewODCompareProc( DrawCompare ) ;
- helper->InstallCompareProc(compUPP, (ODSLong)session);
-
- ODCountUPP countUPP = NewODCountProc( DrawCount ) ;
- helper->InstallCountProc(countUPP, (ODSLong)session);
-
- ODDisposeTokenUPP disposeTokenUPP
- = NewODDisposeTokenProc( DrawDisposeToken ) ;
- helper->InstallDisposeTokenProc( disposeTokenUPP, (ODSLong)session);
-
- // Environment* ev = somGetGlobalEnvironment();
- // semtIntf->SetOSLSupportFlags(ev, kAEIDoWhose);
- }
-
- //------------------------------------------------------------------------------
- // GetPropertyFromNULL
- //------------------------------------------------------------------------------
-
- //#ifdef ODDeleteObject
- //#undef ODDeleteObject
- //#endif
- //#define ODDeleteObject(x)
-
- AEDesc tokenDesc;
- //$$$$$
-
- CONTAINER_ACCESSOR_RETURN_TYPE GetPropertyFromNULL(ODOBJECT_ACCESSOR_PARAMS)
- {
- ODUnused(desiredClass);
- ODUnused(container);
- ODUnused(containerClass);
-
- Environment* ev = somGetGlobalEnvironment();
- ODSession* session = (ODSession*)refCon;
- ODNameResolver* resolver = session->GetNameResolver(ev);
- DescType propID;
- DrawPartPropAccessor* accessorObj;
- ODError error = noErr;
-
- TRY
-
- if (form != formPropertyID)
- THROW(errAEWrongDataType);
-
- AEDesc realData;
- THROW_IF_ERROR( ODDescToAEDesc( selectionData, &realData ) );
-
- propID = **(DescType**)(realData.dataHandle);
- (void)AEDisposeDesc( &realData );
-
- switch( propID )
- {
- // case pBounds:
- case pColor:
- // case pName: // <eeh> removed because of conflict with user name
- if ( !resolver->IsODToken( ev, value ) )
- THROW( errAENoSuchObject );
- tokenDesc.descriptorType = cProperty;
- tokenDesc.dataHandle = NewHandle(sizeof(accessorObj));
- THROW_IF_ERROR(MemError());
-
- ODPart* contextPart;
- ODFrame* contextFrame;
- resolver->GetContextFromToken( ev, container, &contextPart,
- &contextFrame);
-
- accessorObj = new DrawPartPropAccessor(propID, contextFrame);
- SETFIRSTBYTESOFHANDLE(tokenDesc.dataHandle, DrawPartPropAccessor*,
- accessorObj);
- // ODDesc* usrTokenWrapper = new ODDesc();
- // usrTokenWrapper->InitODDesc(ev);
- // THROW_IF_ERROR( AEDescToODDesc( &tokenDesc, usrTokenWrapper ) );
- // resolver->SetUserToken(ev, value, usrTokenWrapper);
- // ODDeleteObject( usrTokenWrapper );
- ODDesc* userODDesc = resolver->GetUserToken(ev, value);
- THROW_IF_ERROR( AEDescToODDesc( &tokenDesc, userODDesc ) );
- AEDisposeDesc(&tokenDesc);
- break;
- default:
- // THROW(errAECantSupplyType);
- THROW(errAEEventNotHandled); // let the default try
- break;
- }
-
- CATCH_ALL
- error = ErrorCode();
- ENDTRY
-
- return error;
- } // GetPropertyFromNULL()
-
-
-
- //------------------------------------------------------------------------------
- // GetPartFromNULL
- //------------------------------------------------------------------------------
-
- CONTAINER_ACCESSOR_RETURN_TYPE GetPartFromNULL(ODOBJECT_ACCESSOR_PARAMS)
- {
- ODUnused(desiredClass);
- ODUnused(container);
- ODUnused(containerClass);
-
- ODUnused(part);
- ODUnused(form);
- ODUnused(selectionData);
- ODUnused(value);
- ODUnused(refCon);
- #if 0
- Environment* ev = somGetGlobalEnvironment();
- ODSession* session = (ODSession*)refCon;
- ODNameResolver* resolver = session->GetNameResolver(ev);
- ODSLong partCount;
- ODSLong theIndex;
- ODBoolean allFlag;
- ODBoolean zeroFlag;
- ODError result;
- ODUShort i;
- ODFrame* frame;
- AEDesc listItem;
- ODError error = noErr;
- #endif
-
- return errAEEventNotHandled;
- #if 0
- if ( !resolver->IsODToken( ev, value ) )
- return errAENoSuchObject;
-
- AEDesc realData;
- ODError err = ODDescToAEDesc( selectionData, &realData );
- if ( err )
- return err;
-
- TRY
-
- partCount = (((AppleTest_Container*)part)->GetEmbeddedFrames(ev))->Count();
-
- if (partCount != 0)
- {
- switch (form)
- {
- case formAbsolutePosition:
- // Are we being asked for and indexed part
- // or for all parts?
- result = DecodeOrdinal(realData, (long)partCount,
- (long*)&theIndex, (Boolean*)&allFlag, (Boolean*)&zeroFlag);
- THROW_IF_ERROR(result);
-
- if (allFlag)
- {
- //THROW(errAENoSuchObject); // don't do lists anymore....
- THROW(errAEEventNotHandled); // don't do lists anymore....
- AEDesc listOfTokens;
- result = AECreateList( kODNULL, 0, kODFalse, &listOfTokens );
- THROW_IF_ERROR(result);
-
- // Get theEmbeddedPart number theIndex
- DrawEmbeddedFramesIterator* iter =
- (DrawEmbeddedFramesIterator*)part->CreateEmbeddedFramesIterator(ev, kODNULL);
- for (frame = iter->First(ev), i=1; iter->IsNotComplete(ev); frame = iter->Next(ev), i++)
- {
- if (frame)
- {
- listItem.descriptorType = kODStandardPartTokenType;
- listItem.dataHandle = NewHandle(sizeof(StandardPartToken));
- THROW_IF_ERROR(MemError());
-
- StandardPartToken spt;
- spt.fPart = frame->AcquirePart(ev);
- spt.fFrame = frame;
-
- SETFIRSTBYTESOFHANDLE(listItem.dataHandle,
- StandardPartToken, spt );
-
- result = AEPutDesc(&listOfTokens, i, &listItem);
- THROW_IF_ERROR(result);
-
- result = AEDisposeDesc(&listItem);
- THROW_IF_ERROR(result);
- }
- }
- // ODDesc* wrapperDesc = new ODDesc();
- // wrapperDesc->InitODDesc(ev);
- // THROW_IF_ERROR( AEDescToODDesc( &listOfTokens, wrapperDesc ) );
- // resolver->SetUserToken(ev, value, wrapperDesc);
- // ODDeleteObject( wrapperDesc );
- UpdateUserToken(ev, resolver, value, &listOfTokens);
- }
- else
- {
- // Get theEmbeddedPart number theIndex
- DrawEmbeddedFramesIterator* iter =
- (DrawEmbeddedFramesIterator*)part->
- CreateEmbeddedFramesIterator(ev, kODNULL);
- for (frame = iter->First(ev), i=1; iter->IsNotComplete(ev); frame = iter->Next(ev), i++)
- {
- if (i == theIndex)
- {
- break;
- }
- }
-
- if (frame)
- {
- AEDesc myToken;
- myToken.descriptorType = kODStandardPartTokenType;
- myToken.dataHandle = NewHandle(sizeof(StandardPartToken));
- THROW_IF_ERROR(MemError());
-
- StandardPartToken spt;
- spt.fPart = frame->AcquirePart(ev);
- spt.fFrame = frame;
-
- SETFIRSTBYTESOFHANDLE(myToken.dataHandle,
- StandardPartToken, spt );
-
- // ODDesc* wrapperDesc = new ODDesc();
- // wrapperDesc->InitODDesc(ev);
- // THROW_IF_ERROR( AEDescToODDesc( &myToken, wrapperDesc ) );
- // resolver->SetUserToken(ev, value, wrapperDesc);
- // ODDeleteObject( wrapperDesc );
- UpdateUserToken(ev, resolver, value, &myToken);
- }
- else
- //THROW(errAENoSuchObject);
- THROW(errAEEventNotHandled);
- }
- break;
- default:
- //THROW(errAENoSuchObject);
- THROW(errAEEventNotHandled);
- break;
- }
- }
- else
- //THROW(errAENoSuchObject);
- THROW(errAEEventNotHandled);
-
- CATCH_ALL
- error = ErrorCode();
- ENDTRY
-
- (void)AEDisposeDesc( &realData );
- return error;
- #endif // 0
- } // GetPartFromNULL()
-
- //------------------------------------------------------------------------------
- // GetPropertyFromPart
- //------------------------------------------------------------------------------
-
- CONTAINER_ACCESSOR_RETURN_TYPE GetPropertyFromPart(ODOBJECT_ACCESSOR_PARAMS)
- {
- ODUnused(desiredClass);
- ODUnused(containerClass);
-
- ODUnused(part);
- ODUnused(form);
- ODUnused(selectionData);
- ODUnused(value);
- ODUnused(refCon);
- #if 0
- Environment* ev = somGetGlobalEnvironment();
- ODSession* session = (ODSession*)refCon;
- ODNameResolver* resolver = session->GetNameResolver(ev);
- DescType propID;
- ODError error = noErr;
-
- ODDesc* token;
- token = resolver->GetUserToken(ev, container);
- AEDesc tokenDesc;
- error = ODDescToAEDesc( token, &tokenDesc );
- if ( error )
- return error;
-
- TRY
-
- if (form != formPropertyID)
- THROW(errAEWrongDataType);
- if( tokenDesc.descriptorType != kODStandardPartTokenType )
- THROW(errAEWrongDataType);
-
- StandardPartToken spt = FIRSTBYTESFROMHANDLE( tokenDesc.dataHandle,
- StandardPartToken );
- if( !spt.fFrame )
- THROW(errAENoSuchObject);
-
- AEDesc realSelData;
- THROW_IF_ERROR( ODDescToAEDesc( selectionData, &realSelData ) );
-
- propID = **(DescType**)(realSelData.dataHandle);
- switch (propID)
- {
- case pTranslation:
- case pBounds:
- if ( !resolver->IsODToken( ev, value ) )
- THROW( errAENoSuchObject );
- EmbeddedPartPropAccessor* accessorObj;
- AEDesc tokenDesc;
- tokenDesc.descriptorType = typeEmbededPartProp;
- tokenDesc.dataHandle = NewHandle(sizeof(accessorObj));
- THROW_IF_ERROR(MemError());
-
- accessorObj = new EmbeddedPartPropAccessor(propID, spt.fFrame,
- (AppleTest_Container*)part);
- SETFIRSTBYTESOFHANDLE(tokenDesc.dataHandle,EmbeddedPartPropAccessor*,
- accessorObj);
-
- // ODDesc* wrapperDesc = new ODDesc();
- // wrapperDesc->InitODDesc(ev);
- // THROW_IF_ERROR( AEDescToODDesc( &tokenDesc, wrapperDesc ) );
- // resolver->SetUserToken(ev, value, wrapperDesc);
- // ODDeleteObject( wrapperDesc );
- UpdateUserToken(ev, resolver, value, &tokenDesc);
- break;
- default:
- resolver->CreateSwapToken(ev, value, spt.fPart, spt.fFrame);
- break;
- }
-
-
- CATCH_ALL
- error = ErrorCode();
- ENDTRY
-
- return error;
- #endif
- return errAEEventNotHandled;
- } // GetPropertyFromPart()
-
- //------------------------------------------------------------------------------
- // GetWildcardFromPart
- //------------------------------------------------------------------------------
-
- CONTAINER_ACCESSOR_RETURN_TYPE GetWildcardFromPart(ODOBJECT_ACCESSOR_PARAMS)
- {
- ODUnused(part);
- ODUnused(desiredClass);
- ODUnused(containerClass);
- ODUnused(form);
- ODUnused(selectionData);
- #if 0 //#
- Environment* ev = somGetGlobalEnvironment();
- ODError error = noErr;
-
- TRY
-
- // we need to just return a switch here: we can't go into the part.
- ODNameResolver* resolver = ((ODSession*)refCon)->GetNameResolver(ev);
-
- if ( !resolver->IsODToken( ev, value ) )
- THROW( errAENoSuchObject );
- AEDesc containerToken;
- resolver->GetUserToken( ev, container, &containerToken );
-
- // REMEMBER: I don't know what kind of part this is!
- ODFrame* frame = FIRSTBYTESFROMHANDLE(containerToken.dataHandle, ODFrame*);;
-
- resolver->CreateSwapToken(ev, value, frame);
-
- CATCH_ALL
- error = ErrorCode();
- ENDTRY
-
- return error;
- #endif // 0 //#
- return errAEEventNotHandled; //#
- } // GetWildcardFromPart()
-
-
- //------------------------------------------------------------------------------
- // GetWildcardFromList
- //------------------------------------------------------------------------------
-
- CONTAINER_ACCESSOR_RETURN_TYPE GetWildcardFromList(ODOBJECT_ACCESSOR_PARAMS)
- {
- ODUnused(containerClass);
- #if 0 //#
- ODError result;
- ODSLong itemCount;
- AEKeyword theAEKeyword;
- ODOSLToken thisItem;
- ODOSLToken myToken;
- ODSLong i;
- ODError error = noErr;
-
- TRY
-
- Environment* ev = somGetGlobalEnvironment();
- ODSession* session = (ODSession*)refCon;
- ODNameResolver* resolver = session->GetNameResolver(ev);
-
- result = AECountItems(container, &itemCount);
- THROW_IF_ERROR(result);
-
- result = AECreateList(nil,0,false,value);
- THROW_IF_ERROR(result);
-
- for (i=1;i<=itemCount;++i)
- {
- result = AEGetNthDesc(container,i,typeWildCard,
- &theAEKeyword, &thisItem);
- THROW_IF_ERROR(result);
-
- resolver->CallObjectAccessor(ev, thisPart, desiredClass, &thisItem,
- thisItem.descriptorType, form, selectionData,
- &myToken);
-
- result = AEPutDesc(value, 0, &myToken);
- THROW_IF_ERROR(result);
-
- result = AEDisposeDesc(&thisItem);
- THROW_IF_ERROR(result);
-
- result = AEDisposeDesc(&myToken);
- THROW_IF_ERROR(result);
- }
-
- CATCH_ALL
- error = ErrorCode();
- ENDTRY
-
- return error;
- #endif // 0 //#
- return errAEEventNotHandled; //#
- } // GetWildcardFromList()
-
-
- //------------------------------------------------------------------------------
- // HandleSetData
- //------------------------------------------------------------------------------
-
- CONTAINER_ACCESSOR_RETURN_TYPE HandleSetData(ODEVENT_HANDLER_PARAMS)
- {
- ODUnused(part);
- ODUnused(reply);
-
- AEDesc theData;
- ODError error = noErr;
-
- Environment* ev = somGetGlobalEnvironment();
- ODNameResolver* resolver =
- ((ODSession*)handlerRefcon)->GetNameResolver(ev);
-
- AppleEvent realMessage, realReply;
- THROW_IF_ERROR( ODDescToAEDesc(message, &realMessage) );
- THROW_IF_ERROR( ODDescToAEDesc(reply, &realReply ));
-
- ODOSLToken* tmpWrapper = kODNULL;
- TRY
-
- THROW_IF_ERROR(AEGetKeyDesc(&realMessage, keyAEData,
- typeWildCard, &theData));
-
- AEDesc evtDp;
- GetDirectParam( (ODSession*)handlerRefcon, &realMessage, &evtDp);
- tmpWrapper = new ODOSLToken();
- THROW_IF_NULL(tmpWrapper);
- tmpWrapper->InitODOSLToken(ev);
- THROW_IF_ERROR( AEDescToODDesc(&evtDp, tmpWrapper ) );
- if ( !resolver->IsODToken( ev, tmpWrapper ) )
- THROW( errAENoSuchObject );
- ODDesc* myTokenODDesc;
- myTokenODDesc = resolver->GetUserToken(ev, tmpWrapper);
- AEDesc theToken;
- error = ODDescToAEDesc(myTokenODDesc, &theToken );
-
- if (error == noErr)
- {
- switch (theToken.descriptorType)
- {
- case typeEmbededPartProp:
- case typeFrameProp:
- case typeProperty:
- AbsDrawPartPropAccessor* embedPropAccessorObj =
- FIRSTBYTESFROMHANDLE(theToken.dataHandle, AbsDrawPartPropAccessor*);
- embedPropAccessorObj->SetData(&theData);
- // delete embedPropAccessorObj;
- break;
- case typeDPElem:
- DrawPartElemAccessor* elemAccessorObj = FIRSTBYTESFROMHANDLE(
- theToken.dataHandle, DrawPartElemAccessor* );
- elemAccessorObj->SetData(&theData);
- // delete elemAccessorObj;
- break;
-
- default:
- //ASSERTM(false, errAECantSupplyType, "You shouldn't be here");
- THROW(errAEEventNotHandled);
- }
- }
- AEDisposeDesc(&theData);
- THROW_IF_ERROR(error);
-
- CATCH_ALL
- error = ErrorCode();
- ENDTRY
-
- ODDeleteObject( tmpWrapper );
- return error;
- } // HandleSetData()
-
-
- //------------------------------------------------------------------------------
- // HandleGetData
- //------------------------------------------------------------------------------
-
- CONTAINER_ACCESSOR_RETURN_TYPE HandleGetData(ODEVENT_HANDLER_PARAMS)
- {
- ODUnused(part);
- ODUnused(handlerRefcon);
-
- DescType reqType;
- Size theSize;
- AEDesc objectData;
- ODError error;
- Environment* ev = somGetGlobalEnvironment();
- ODNameResolver* resolver =
- ((ODSession*)handlerRefcon)->GetNameResolver(ev);
- AEDesc token = NULL_DESCRIPTOR_DEFINITION;
-
- AppleEvent realMessage = NULL_DESCRIPTOR_DEFINITION;
- AppleEvent realReply = NULL_DESCRIPTOR_DEFINITION;
-
- THROW_IF_ERROR( ODDescToAEDesc(message, &realMessage));
- THROW_IF_ERROR( ODDescToAEDesc(reply, &realReply));
-
- ODOSLToken* tmpWrapper = kODNULL;
-
- ODVolatile(tmpWrapper);
- ODVolatile(error);
-
- TRY
- AEDesc evtDp;
- GetDirectParam( (ODSession*)handlerRefcon, &realMessage, &evtDp);
- tmpWrapper = new ODOSLToken();
- THROW_IF_NULL(tmpWrapper);
- tmpWrapper->InitODOSLToken(ev);
- THROW_IF_ERROR( AEDescToODDesc(&evtDp, tmpWrapper ) );
- AEDisposeDesc(&evtDp);
- if ( !resolver->IsODToken( ev, tmpWrapper ) )
- THROW( errAENoSuchObject );
- ODDesc* myTokenODDesc;
- myTokenODDesc = resolver->GetUserToken(ev, tmpWrapper);
- THROW_IF_ERROR( ODDescToAEDesc(myTokenODDesc, &token ) );
-
- // Next, get the requested return type, if it exists.
- error = AEGetParamPtr(&realMessage, keyAERequestedType, typeType,
- &reqType, (Ptr)&reqType, sizeof(reqType), &theSize);
- AEDisposeDesc( &realMessage );
- if (error == errAEDescNotFound) // Not an error if return type is not found.
- {
- error = noErr;
- reqType = typeWildCard;
- }
- THROW_IF_ERROR(error);
-
- switch (token.descriptorType)
- {
- case typeEmbededPartProp:
- case typeFrameProp:
- case typeProperty:
- AbsDrawPartPropAccessor* propAccessorObj = FIRSTBYTESFROMHANDLE(
- token.dataHandle, AbsDrawPartPropAccessor*);
- propAccessorObj->GetData(&objectData);
- // delete propAccessorObj;
- break;
- case typeDPElem:
- DrawPartElemAccessor* elemAccessorObj = FIRSTBYTESFROMHANDLE(
- token.dataHandle, DrawPartElemAccessor* );
- elemAccessorObj->GetData(&objectData);
- // delete elemAccessorObj;
- break;
-
- default:
- //ASSERTM(false, errAECantSupplyType, "You shouldn't be here");
- THROW(errAEEventNotHandled);
-
- }
-
- AEDisposeDesc(&token);
-
- error = AEPutParamDesc( &realReply, keyAEResult, &objectData );
- AEDisposeDesc( &objectData );
-
- THROW_IF_ERROR(error);
-
- THROW_IF_ERROR( AEDescToODDesc( &realReply, reply ) );
- AEDisposeDesc( &realReply );
- CATCH_ALL
- ODDisposeAppleEvent(&realMessage);
- ODDisposeAppleEvent(&realReply);
- AEDisposeDesc(&token);
- error = ErrorCode();
- ENDTRY
-
- ODDeleteObject( tmpWrapper );
- return error;
- } // HandleGetData()
-
- //------------------------------------------------------------------------------
- // HandleCreate
- //------------------------------------------------------------------------------
-
- // This guy translates the name of the user's new part into a class that
- // we can actually use. Or at least I think that's how it will work.
-
- static DescType Partstring2Type(AEDesc* thePartType)
- {
- DescType result = cDrawPart; // default (for now)
-
- if(thePartType->dataHandle != NULL)
- {
- HLock(thePartType->dataHandle);
- short len = (short)GetHandleSize(thePartType->dataHandle);
-
- char* drawpart = "drawpart";
- char* dragpart = "dragpart";
- char* clockpart = "clockpart";
- char* testpart = "testpart";
- if (IUMagString(*thePartType->dataHandle, drawpart, len,
- strlen(drawpart)) == 0)
- result = cDrawPart;
- else if (IUMagString(*thePartType->dataHandle, dragpart, len,
- strlen(dragpart)) == 0)
- result = cDragPart;
- else if (IUMagString(*thePartType->dataHandle, clockpart, len,
- strlen(clockpart)) == 0)
- result = cClockPart;
- else if (IUMagString(*thePartType->dataHandle, testpart, len,
- strlen(testpart)) == 0)
- result = cTestPart;
-
- AEDisposeDesc(thePartType);
- }
- return result;
-
- } // Partstring2Type()
-
- CONTAINER_ACCESSOR_RETURN_TYPE HandleRevert(ODEVENT_HANDLER_PARAMS)
- {
- SysBeep(9);
- SysBeep(9);
- SysBeep(9);
- return noErr;
- }
-
- CONTAINER_ACCESSOR_RETURN_TYPE HandleCreate(ODEVENT_HANDLER_PARAMS)
- {
- ODUnused(part);
- ODUnused(reply);
- ODUnused(handlerRefcon);
- #if 0
- Environment* ev = somGetGlobalEnvironment();
- ODError result;
- DescType theType;
- DescType theClass;
- ODSize theSize;
- AEDesc replyObject;
- ODPart* theNewPart;
- ODError error = noErr;
-
- TRY
-
- // First, get the object class -- a required parameter
- result = AEGetParamPtr(message, keyAEObjectClass, typeType, &theType,
- (Ptr)&theClass, sizeof(DescType), (Size *)&theSize);
- THROW_IF_ERROR(result);
-
- if(theClass != cPart)
- THROW(errAENoSuchObject);
-
- AEDesc thePartType;
- ThrowIfNotAbsent(AEGetParamDesc(message, typeType, typeChar,
- &thePartType));
- DescType partKind = Partstring2Type(&thePartType);
-
- // Next, get the insertion location -- a required parameter
- AEDesc theLocation;
- result = AEGetParamDesc(message, keyAEInsertHere, typeInsertionLoc,
- &theLocation);
- if (result != errAEDescNotFound)
- THROW_IF_ERROR(result);
-
- // Create the new part
- theNewPart=((AppleTest_Container*)part)->CreateNewPart(ev, partKind, &theLocation);
-
- // have the new part create an object specifier for itself
- AEDesc containerObjSpec;
- THROW_IF_ERROR(AEGetAttributeDesc(message, 'subj',
- typeObjectSpecifier, &containerObjSpec));
- CreatePartObjectSpec(formAbsolutePosition, &containerObjSpec, &replyObject);
- AEDisposeDesc(&containerObjSpec);
-
- // put the object spec in the result field of reply
- result = AEPutParamDesc(reply, keyAEResult, &replyObject);
- AEDisposeDesc(&replyObject);
- THROW_IF_ERROR(result);
-
- // <eeh> But I want it to stick around!!!!
- // delete theNewPart;
- // ODReleaseObject(theNewPart);
-
- CATCH_ALL
- error = ErrorCode();
- ENDTRY
-
- return error;
- #endif /* 0 */
- return errAEEventNotHandled;
- } // HandleCreate()
-
- //------------------------------------------------------------------------------
- // HandleMove
- //
- // ALL THIS HANDLES right now is moving a part's frame[s], though I've
- // never tested it on any part with more than one frame!
- //------------------------------------------------------------------------------
-
- static void MoveFacetTransform(ODFacet* facet, Point* desiredLocation,
- ODPart* part)
- {
- #if 0
- // DMc refcount - comment out lines to make refbal ignore them
- // Environment* ev = somGetGlobalEnvironment();
- // ODTransform* newXForm = ODCopyAndRelease(facet->GetExternalTransform(ev));
- // Point curOffset = newXForm->GetQDOffset(ev);
- // Point scratch = *desiredLocation;
- // scratch.h -= curOffset.h;
- // scratch.v -= curOffset.v;
- //
- // ODPoint newDelta = *desiredLocation = scratch;
- // newXForm->MoveBy(ev, &newDelta);
- // facet->ChangeGeometry(ev, kODNULL, newXForm);
- // facet->Invalidate(ev, kODNULL);
- #endif /* 0 */
- }
-
- CONTAINER_ACCESSOR_RETURN_TYPE HandleMove(ODEVENT_HANDLER_PARAMS)
- {
- #if 0
- // DMc refcount - comment out lines to make refbal ignore them
- // ODUnused(handlerRefcon);
- // ODUnused(reply);
- //
- // Environment* ev = somGetGlobalEnvironment();
- // AppleTest_Container* thisDrawPart = (AppleTest_Container*) part;
- //
- // // Size theSize;
- // // DescType theType;
- // ODError error = noErr;
- //
- // TRY
- //
- // AEDesc destination; // where it's to be moved to
- // OSErr result = AEGetParamDesc(message, keyAEInsertHere, typeWildCard,
- // &destination);
- // THROW_IF_ERROR(result);
- //
- // ODOSLToken theToken; // what I'm supposed to move
- // THROW_IF_ERROR(AEGetParamDesc(message, keyDirectObject, typeWildCard,
- // &theToken));
- // if ((&theToken)->descriptorType != cPart)
- // THROW();
- //
- // if (destination.descriptorType == typeObjectSpecifier) // a path
- // {
- // ODOSLToken token;
- //
- // ODNameResolver* resolver = ((ODSession*)handlerRefcon)->
- // GetNameResolver(ev);
- // // start resolution at the shell
- // resolver->Resolve(&destination, &token, kODAppShell);
- //
- // // now replace the location with the token, and pass the
- // // event to that part. should I dispose of the token after
- // // putting it in the AppleEvent?
- //
- // THROW_IF_ERROR(AEPutParamDesc(message, keyAEInsertHere,
- // &token));
- // ODPart* embedder;
- // ODFrame* ignoreF;
- // resolver->GetContextInfo(ev, &ignoreF, &embedder);
- // ODMessageInterface* msgInterface = ((ODSession*)handlerRefcon)->
- // GetMessageInterface(ev);
- // // NO! PRIVATE METHOD. MUST USE SEND.
- // THROW_IF_ERROR(msgInterface->DispatchToEventHandler(message,
- // reply, embedder));
- //
- // }
- // else if (destination.descriptorType == cPart)
- // {
- // // Here the destination is a token belonging to me. As the
- // // embedding part (the last to deal with the token before the
- // // original recipient of the event finished resolving it) I
- // // own the destination and can get out of the token what I
- // // need.
- //
- // ODFrame* frameToMoveTo = (ODFrame*)
- // GetSecondFourBytesFromDataHandle(&destination);
- // ODFrame* frameToMove
- // = (ODFrame*)GetSecondFourBytesFromDataHandle(&theToken);
- //
- //
- // // get some info for the embed call
- // ODShape* frameShape = ODCopyAndRelease(frameToMove->GetFrameShape(ev));
- //
- // ODTransform* xtrnlXfrm = ODCopyAndRelease(facet->GetExternalTransform(ev));
- // ODFrameFacetIterator* fi = frameToMove->CreateFacetIterator(ev);
- // ODFacet* facet = fi->First(ev);
- //
- //
- // // remove the frame from the old place
- // frameToMove->GetContainingFrame(ev)->GetPart(ev)->
- // RemoveEmbeddedFrame(ev, frameToMove);
- //
- // // embed it in the new
- //
- // WASSERT(part == frameToMoveTo->GetPart(ev));
- //
- // ODFrame* newFrame = thisDrawPart->CreateEmbeddedFrame(ev,
- // frameToMoveTo,
- // frameShape,
- // xtrnlXfrm,
- // frameToMove->GetPart(ev),
- // kODNullTypeToken,
- // kODNullTypeToken,
- // 0,
- // kODFalse);
- // ODReleaseObject(ev, frameShape);
- // ODReleaseObject(ev, xtrnlXfrm);
- // }
- // else
- // {
- // // get the point
- // AEDesc dPoint;
- // result = AECoerceDesc(&destination, typeQDPoint, &dPoint);
- // THROW_IF_ERROR(result);
- // Point pt = **(Point**)dPoint.dataHandle;
- // AEDisposeDesc(&dPoint);
- //
- // ODFrame* frameToMove
- // = (ODFrame*)GetSecondFourBytesFromDataHandle(&theToken);
- // ODFrameFacetIterator* fi = frameToMove->CreateFacetIterator(ev);
- // ODFacet* facet = fi->First(ev);
- // MoveFacetTransform(facet, &pt, frameToMove->GetPart(ev));
- //
- // Proxy* p = thisDrawPart->ProxyForFrame(frameToMove);
- //
- // // !!! this is a single-facet hack
- // p->transform->MoveBy(ev, pt);
- // thisDrawPart->UpdateProxyRegion(ev, p);
- // thisDrawPart->CreateProxySelectionBorder(ev, p);
- //
- // frameToMove->GetContainingFrame(ev)->Invalidate(ev, (ODShape*)kODNULL);
- // }
- //
- // AEDisposeDesc(&destination);
- //
- // CATCH_ALL
- // error = ErrorCode();
- // ENDTRY
- //
- // return error;
- #endif /* 0 */
- return errAEEventNotHandled;
- } // HandleMove()
-
- //------------------------------------------------------------------------------
- // Coercelist2RGB
- //
- // From the AppleScript code and tweaked.
- //------------------------------------------------------------------------------
-
- #define QDRGBsize 3
-
- CONTAINER_ACCESSOR_RETURN_TYPE CoerceList2RGB(ODPart* part, AEDesc* from, DescType toType,
- ODSLong refcon, AEDesc* result)
- {
- ODUnused(part);
- ODUnused(refcon);
-
- OSErr err;
- AEKeyword dummyKeyword;
- DescType dummyCode;
- Size itemSize;
- long theData[QDRGBsize];
- unsigned short theRealData[QDRGBsize];
- ODError error = noErr;
-
- TRY
-
- // the data goes R, G, B
- for (int i=0; i<QDRGBsize; i++) {
- err = AEGetNthPtr(from, i+1, typeLongInteger, &dummyKeyword,
- &dummyCode, (Ptr) &theData[i], sizeof(theData[0]),
- &itemSize);
- if ((err != noErr) || (theData[i] < 0) || (theData[i] > USHRT_MAX))
- THROW(errAECoercionFail);
- theRealData[i] = (unsigned short)theData[i];
- }
- THROW_IF_ERROR(AECreateDesc(toType, (Ptr)&theRealData,
- QDRGBsize * sizeof(short), result));
-
- CATCH_ALL
- error = ErrorCode();
- ENDTRY
-
- return error;
- }
-
- //------------------------------------------------------------------------------
- // DrawCompare
- // For now, just handle what we need to handle
- //------------------------------------------------------------------------------
- CONTAINER_ACCESSOR_RETURN_TYPE DrawCompare( ODPart* thePart,
- DescType oper,
- ODOSLToken* obj1,
- ODOSLToken* obj2,
- ODBoolean* result,
- ODSLong refCon)
- {
- ODUnused(thePart);
-
- Environment* ev = somGetGlobalEnvironment();
- ODError error = noErr;
- ODDesc* tokenWrapper1;
- ODDesc* tokenWrapper2;
- AEDesc realToken1 = NULL_DESCRIPTOR_DEFINITION;
- AEDesc realToken2 = NULL_DESCRIPTOR_DEFINITION;
-
- TRY
- ODNameResolver* resolver = ((ODSession*)refCon)->GetNameResolver(ev);
-
- switch(oper)
- {
- case kAEEquals:
-
- if ( resolver->IsODToken( ev, obj1 ) )
- {
- tokenWrapper1 = resolver->GetUserToken( ev, obj1 );
- THROW_IF_ERROR( ODDescToAEDesc( tokenWrapper1, &realToken1 ) );
- }
- else THROW_IF_ERROR( ODDescToAEDesc( obj1, &realToken1 ) );
-
- if ( resolver->IsODToken( ev, obj2 ) )
- {
- tokenWrapper2 = resolver->GetUserToken( ev, obj2 );
- THROW_IF_ERROR( ODDescToAEDesc( tokenWrapper2, &realToken2 ) );
- }
- else THROW_IF_ERROR( ODDescToAEDesc( obj2, &realToken2 ) );
-
- if ( ( realToken1.descriptorType == typeDPElem )
- || ( realToken2.descriptorType == typeDPElem ) )
- *result = CompareDPElemsAndChars( &realToken1, &realToken2 );
- else
- error = errAEEventNotHandled;
-
- AEDisposeDesc(&realToken1);
- AEDisposeDesc(&realToken2);
-
- break;
-
- default:
- THROW(errAEEventNotHandled);
- }
-
- CATCH_ALL
- AEDisposeDesc(&realToken1);
- AEDisposeDesc(&realToken2);
- error = ErrorCode();
- ENDTRY
-
- return error;
- } //DrawCompare
-
- //------------------------------------------------------------------------------
- // DrawCount
- //------------------------------------------------------------------------------
- CONTAINER_ACCESSOR_RETURN_TYPE DrawCount( ODPart* thePart,
- DescType desiredType,
- DescType containerClass,
- ODOSLToken* container,
- ODSLong* result,
- ODSLong refCon)
- {
- Environment* ev = somGetGlobalEnvironment();
- ODError error = noErr;
- ODIText* iText = kODNULL;
-
- TRY
- ODNameResolver* resolver =
- ((ODSession*)refCon)->GetNameResolver(ev);
-
- if ( !resolver->IsODToken(ev, container) )
- THROW(errAEEventNotHandled);
-
- if ( (containerClass == typeNull ) && ( desiredType == cChar ) )
- {
- ODFrame* frame;
- ODPart* ignorePart;
- resolver->GetContextFromToken( ev, container, &ignorePart, &frame );
- iText = ODGetComments( ev, frame, kODNULL );
- if (!iText)
- *result = 0;
- else
- *result = GetITextStringLength(iText);
- }
- else if (containerClass == cPart)
- {
- //ODDesc* tokenWrapper;
- //resolver->GetUserToken( ev, container, &tokenWrapper );
- //AEDesc token;
- //THROW_IF_ERROR( ODDescToAEDesc( tokenWrapper, &token ) );
- //WASSERT( token.descriptorType == kODStandardPartTokenType );
-
- //StandardPartToken spt = FIRSTBYTESFROMHANDLE(token.dataHandle,
- //StandardPartToken);
- //WARN( "I've got the part but nothing to do with it...." );
- // resolver->CreateSwapToken(value, part);
- *result = kODCountProcSwapValue;
- }
- else if (containerClass == typeNull && desiredType == cPart)
- *result = CountEmbeddedParts(ev, thePart);
- else
- error = errAEEventNotHandled;
- CATCH_ALL
- error = ErrorCode();
- ENDTRY
-
- if ( iText != kODNULL) DisposeIText(iText);
-
- return error;
- //# return errAEEventNotHandled;
- } //DrawCount
-
- //------------------------------------------------------------------------------
- // DrawDisposeToken
- //------------------------------------------------------------------------------
- CONTAINER_ACCESSOR_RETURN_TYPE DrawDisposeToken(ODPart* thePart,
- ODOSLToken* unneededToken,
- ODSLong refCon)
- {
- ODUnused(thePart);
-
- ODSession* session = (ODSession*)refCon;
- Environment* ev = somGetGlobalEnvironment();
- ODNameResolver* resolver = session->GetNameResolver(ev);
- ODBoolean oneOfOurs = kODFalse;
- ODByteArray data;
-
- ODDescType temp = unneededToken->GetDescType(ev);
- if (resolver->IsODToken( ev, unneededToken ))
- {
- ODDesc* userTokenODDesc = resolver->GetUserToken( ev, unneededToken );
- ODDescType descType = userTokenODDesc->GetDescType(ev);
-
-
- /* CAN"T DEAL WITH cProperty YET BECAUSE THE DEFAULT ACCESSORS USE THIS
- DESCRIPTOR TYPE AS WELL. DRAWPART WILL THINK THAT ONE OF THE DEFAULT
- ACCESSORS' TOKENS IS ONE OF ITS OWN AND TRY TO DISPOSE IT. */
-
-
- // BE CAREFUL TO MATCH THE CASES HERE WITH THE CASES IN 2ND SWITCH
- // STATEMENT
- switch(descType)
- {
- // case cProperty:
- case typeEmbededPartProp:
- case typeDPElem:
- oneOfOurs = kODTrue;
- data = userTokenODDesc->GetRawData(ev);
- break;
- }
-
- if (oneOfOurs)
- {
- switch(descType)
- {
- // case cProperty:
- // ODDeleteObject( *((DrawPartPropAccessor**)data._buffer) );
- // break;
- case typeEmbededPartProp:
- ODDeleteObject( *((EmbeddedPartPropAccessor**)data._buffer) );
- break;
- case typeDPElem:
- ODDeleteObject( *((DrawPartElemAccessor**)data._buffer) );
- break;
- default:
- // THE CASES IN THIS SWITCH DO NOT MATCH THE CASES IN THE
- // ABOVE SWITCH
- WARN("DrawDisposeToken: Should never have hit here.");
-
- }
- DisposeByteArrayStruct(data);
- }
- }
-
- // LET OPENDOC DELETE THE TOKEN ITSELF
- return errAEEventNotHandled;
- }
-
- //------------------------------------------------------------------------------
- // Utility functions
- //------------------------------------------------------------------------------
-
- void GetDirectParam(ODSession* session, AppleEvent* message,
- AEDesc* evtDp)
- {
- Environment* ev = somGetGlobalEnvironment();
- AEDesc localDP;
- THROW_IF_ERROR(AEGetParamDesc(message, keyDirectObject, typeWildCard,
- &localDP));
-
- ODNameResolver* resolver = session->GetNameResolver(ev);
-
- ODOSLToken* tmpWrapper = new ODOSLToken();
- THROW_IF_NULL(tmpWrapper);
- tmpWrapper->InitODOSLToken(ev);
- THROW_IF_ERROR( AEDescToODDesc(&localDP, tmpWrapper ) );
-
- ODBoolean isToken = resolver->IsODToken(ev, tmpWrapper);
- ODDeleteObject( tmpWrapper );
- if ( isToken )
- {
- *evtDp = localDP;
- }
- else
- {
- WARN("RlShlEv.cpp: GetDirectParam. Found a non-token. About to throw.");
- THROW( errAEEventNotHandled );
- }
- } // GetDirectParam()
-
- // #undef ODDeleteObject
-
- //------------------------------------------------------------------------------
- // CreatePartObjectSpec
- //------------------------------------------------------------------------------
-
- static void CreatePartObjectSpec(DescType keyForm, AEDesc* containerObjSpec,
- AEDesc *objectSpec)
- {
- // We'll really return a spec to the FRAME containing the part.
- // This cause you can get to the part from the frame, but not the other
- // way 'round.
-
- AEDesc keyData;
-
- switch(keyForm)
- {
- case formAbsolutePosition :
- long index = 1; // <eeh> we should figure out where
- THROW_IF_ERROR(AECreateDesc(typeLongInteger, &index, sizeof(index),
- &keyData));
- break;
- default :
- ASSERTM(false, -1, "Can't handle that form!!! (yet)");
- }
-
- CreateObjSpecifier(cPart, containerObjSpec, keyForm, &keyData, true,
- objectSpec);
- } // CreatePartObjectSpec()
-
- CONTAINER_ACCESSOR_RETURN_TYPE GetCharFromNULL(ODOBJECT_ACCESSOR_PARAMS)
- {
- Environment* ev = somGetGlobalEnvironment();
- ODSession* session = (ODSession*)refCon;
- ODNameResolver* resolver = session->GetNameResolver(ev);
- AEDesc tokenDesc;
- AEDesc realData;
- ODPart* contextPart;
- ODFrame* contextFrame;
- DrawPartElemAccessor* accessorObj = kODNULL;
- ODDesc* usrTokenWrapper = kODNULL;
- ODError error = noErr;
-
- TRY
-
- WASSERT( desiredClass == cChar );
-
- THROW_IF_ERROR( ODDescToAEDesc( selectionData, &realData ) );
-
- if ( !resolver->IsODToken( ev, value ) ) THROW( errAENoSuchObject );
-
- tokenDesc.descriptorType = typeDPElem;
- tokenDesc.dataHandle = NewHandle(sizeof(accessorObj));
- THROW_IF_ERROR( MemError() );
-
- resolver->GetContextFromToken( ev, container, &contextPart, &contextFrame );
-
- accessorObj = new DrawPartElemAccessor();
- accessorObj->InitElemAccessor( desiredClass, form, &realData, contextFrame );
- AEDisposeDesc(&realData);
- SETFIRSTBYTESOFHANDLE( tokenDesc.dataHandle, DrawPartElemAccessor*, accessorObj );
-
- // usrTokenWrapper = new ODDesc();
- // usrTokenWrapper->InitODDesc(ev);
- // THROW_IF_ERROR( AEDescToODDesc( &tokenDesc, usrTokenWrapper ) );
- // resolver->SetUserToken( ev, value, usrTokenWrapper );
- UpdateUserToken(ev, resolver, value, &tokenDesc);
-
- CATCH_ALL
- error = ErrorCode();
-
- // I *THINK* the following is right - probably we need a DisposeProc
- // to handle the internal accessorObj - BHM - NP: This code is fine.
- // Your dispose proc will get called eventually by OpenDoc, and in
- // there, you should dispose of any auxiliary structures.
- if DESC_IS_NOT_NULL(tokenDesc)
- {
- AEDisposeDesc(&tokenDesc); // should be AEDisposeToken - BHM
- // NP: No it shouldn't.
- MAKE_DESC_NULL(tokenDesc);
- }
- ENDTRY
-
- if (usrTokenWrapper != kODNULL) ODDeleteObject(usrTokenWrapper);
-
- return error;
- } // GetCharFromNULL
-
- //------------------------------------------------------------------------------
- // CompareDPElemsAndChars
- //------------------------------------------------------------------------------
- ODBoolean CompareDPElemsAndChars( AEDesc* aDesc, AEDesc* bDesc )
- {
-
- DrawPartElemAccessor* elemAccessorObj;
-
- char char1;
- char char2;
-
- if ( aDesc->descriptorType == typeDPElem )
- {
- elemAccessorObj = FIRSTBYTESFROMHANDLE(
- aDesc->dataHandle, DrawPartElemAccessor* );
- char1 = elemAccessorObj->GetOneChar();
- }
- else char1 = GetOneCharFromDesc(aDesc);
-
- if ( bDesc->descriptorType == typeDPElem )
- {
- elemAccessorObj = FIRSTBYTESFROMHANDLE(
- bDesc->dataHandle, DrawPartElemAccessor* );
- char2 = elemAccessorObj->GetOneChar();
- }
- else char2 = GetOneCharFromDesc(bDesc);
-
- return ( char1 == char2 );
- } //CompareDPElemsAndChars
-
- //------------------------------------------------------------------------------
- // CoerceDPElemToChar
- //------------------------------------------------------------------------------
- CONTAINER_ACCESSOR_RETURN_TYPE CoerceDPElemToChar(ODPart* part, AEDesc* from, DescType toType,
- ODSLong refcon, AEDesc* result)
- {
- DrawPartElemAccessor* fromAccessorObj;
- ODError error = noErr;
-
- MAKE_DESC_NULL(*result);
-
- TRY
- WASSERT( from->descriptorType == typeDPElem );
- WASSERT( toType == typeChar );
-
- fromAccessorObj = FIRSTBYTESFROMHANDLE(
- from->dataHandle, DrawPartElemAccessor* );
-
- fromAccessorObj->GetData(result);
-
- CATCH_ALL
- error = ErrorCode();
- ENDTRY
-
- return error;
- } //CoerceDPElemToChar
-
-
- #undef ODOBJECT_ACCESSOR_PARAMS
-
-
- //------------------------------------------------------------------------------
- // HandleMeow
- //
- // This event is here to test and demonstrate the recipe for accepting an
- // event using either the direct parameter or the subject attribute. It makes
- // use of two routines in SEPriv which are copied into this file,
- // PartFrameFromStandardPartToken and CanBeStandardPartToken. This should
- // enable any container part to determine if an event is targeted at it or
- // not.
- //------------------------------------------------------------------------------
- static pascal ODError HandleMeow( ODPart* part,
- ODAppleEvent* message,
- ODAppleEvent* reply,
- ODSLong handlerRefcon)
- {
- ODError error = noErr;
- ODOSLToken* oslToken;
- ODDesc* userToken = kODNULL;
- ODPart* contextPart = kODNULL;
- ODPart* realPart = kODNULL;
- ODFrame* contextFrame;
- AEDesc realEvent = {typeNull, kODNULL};
- AEDesc obj = {typeNull, kODNULL};
- Environment* ev = somGetGlobalEnvironment();
- ODSession* session = (ODSession*) handlerRefcon;
- ODNameResolver* resolver = session->GetNameResolver(ev);
- ODBoolean samePart = kODFalse;
- ODBoolean disposeToken = kODFalse;
- ODBoolean utilSaysHandle;
-
- /*
- This recipe shows how to work around the fact that events without a
- direct parameter are sent first to the shell (which you'll never notice),
- then to the root part (which you will notice if your part is also the root)
- and then finally to the destination part specified in the subject attribute.
- In addition, it shows how you can determine the destination frame.
-
- Normally, events are sent to the part containing the direct object.
- This is typically the context of the token which OpenDoc replaces the
- actual object specifier with. So normally, you don't even need to look
- at the direct parameter since you are the object which is handling the
- event. However, in the case where the direct parameter is missing, or
- where the direct parameter is a part reference (i.e. part "Bob",
- part id 65535 or part 1 of part 1 of part 1), the dispatching is a bit
- messy due to the fact that you typically want to send the event to the
- container of the object (i.e. the part who contains the thing) so when
- you refer to a part, the container of that part gets the message. Of
- course, there are some caveats as for who "contains" whom. Most notably,
- a "part id 65535" reference is always "contained" by the root part since
- OpenDoc doesn't walk the tree looking for the actual container. That's
- one of the reasons for this recipe. In addition, it turns out that
- the subject attribute is almost always a part reference, so this
- case turns out to almost always be true when the direct parameter is
- missing or is not an object which OpenDoc can resolve.
-
- Also, this code contains provisions for a change in OpenDoc's
- behavior as of 1.2. Prior to 1.2, OpenDoc does not touch the subject
- attribute while after 1.2 OpenDoc replaces the subject attribute with
- the token it got when resolving the subject, just like it does with the
- direct parameter. This code copes with that scenario.
-
- Finally, this code exposes the details about the standard part token,
- which is not made public in the OpenDoc interfaces. Nevertheless, it
- is necessary and accepted that people will be looking at standard part
- tokens, so this is an acceptable way of dealing with life.
- */
-
- TRY
- ODDescToAEDesc(message, &realEvent);
-
- // create an ODOSLToken (which is essentially an ODDesc)
- oslToken = new ODOSLToken;
- THROW_IF_NULL(oslToken);
- oslToken->InitODOSLToken(ev);
-
- // look for and/or at the direct parameter
- error = AEGetKeyDesc(&realEvent, keyDirectObject, typeWildCard, &obj);
- THROW_IF_ERROR( AEDescToODDesc(&obj, oslToken ) );
-
- // if it is missing or not a token then check the subject attribute
- if (error != noErr || !resolver->IsODToken(ev, oslToken)) {
- // there is no direct parameter or it is not an ODToken (i.e. we couldn't resolve it)
- THROW_IF_ERROR( AEGetAttributeDesc(&realEvent, keySubjectAttr, typeWildCard, &obj) );
- if (obj.descriptorType != typeObjectSpecifier) {
- // obj is a token or null
- AEDescToODDesc(&obj, oslToken);
- WASSERT(resolver->IsODToken(ev, oslToken) ||
- oslToken->GetDescType(ev) == typeNull);
- }
- else {
- // the subject was an object so we need to resolve it
-
- // create a wrapper ODObjectSpec (which is just an ODDesc)
- ODObjectSpec* objWrapper = new ODObjectSpec();
- THROW_IF_NULL(objWrapper);
- objWrapper->InitODObjectSpec(ev);
-
- // copy the obj into the ODObjectSpec & dispose of the original
- THROW_IF_ERROR( AEDescToODDesc(&obj, objWrapper ) );
- THROW_IF_ERROR( AEDisposeDesc(&obj) );
-
- // prepare the output ODOSLToken
- oslToken->SetDescType(ev, typeNull);
-
- // resolve the subject attribute & copy the token to obj
- resolver->Resolve(ev, objWrapper, oslToken, kODAppShell);
- THROW_IF_ERROR( ODDescToAEDesc(oslToken, &obj) );
-
- ODDeleteObject(objWrapper);
- disposeToken = kODTrue;
- }
- }
- // At this point both obj & oslToken contain the same data,
- // the token obtained from resolving either the direct parameter
- // or the subject attribute.
- WASSERT(obj.descriptorType == oslToken->GetDescType(ev)); // a cheap check
-
- if (obj.descriptorType != typeNull && obj.dataHandle != kODNULL) {
- // there is an object, so we need to figure out if it is a
- // standard part token and get the part and frame from it or
- // if not, get the context of the token, which should be our part.
- ASSERT(resolver->IsODToken(ev, oslToken), 23);
- userToken = resolver->GetUserToken(ev, oslToken);
- ODDescToAEDesc(userToken, &obj);
- // CanBeStandardPartToken allows developers to make their own tokens
- // which can be coerced into standard part tokens.
- if (CanBeStandardPartToken(&obj)) {
- // A standard part token is merely a part and frame reference, but
- // this routine allows us to hide that info from this code.
- PartFrameFromStandardPartToken(&obj, &contextPart, &contextFrame);
- }
- else {
- // This context was saved during the object resolution and should
- // be the part and frame which contains the object referenced.
- resolver->GetContextFromToken( ev, oslToken, &contextPart, &contextFrame);
- }
- // If we have a frame, then try getting the real part from the part wrapper.
- if (contextFrame) {
- TRY
- realPart = contextPart->GetRealPart(ev);
- samePart = ODObjectsAreEqual(ev, realPart, part);
- contextPart->ReleaseRealPart(ev);
- CATCH_ALL
- WARN("Couldn't get real part, error == %d", ErrorCode());
- ENDTRY
- }
- }
- else {
- // Since we have a null reference, we must be the root frame
- // because without a reference, we can't target anyone else, so
- // we'll grab the front window and get the root frame that way.
- contextFrame = GetDefaultRootFrame(ev, session);
- samePart = kODTrue;
- }
-
- // WARN("Meow - part = %x, wrapper = %x, frame = %x, Parts %s",
- // part, contextPart, contextFrame, samePart ? "match" : "don't match");
-
- // complain if this code and the utility code don't agree
- utilSaysHandle = ShouldHandleEvent(part, message, reply, (ODSession*)handlerRefcon);
- if (utilSaysHandle != samePart) {
- WARN("Meow - I say %shandle it, SEUtils says %shandle it.",
- samePart ? "" : "don't ",
- utilSaysHandle ? "" : "don't ");
- }
-
- // At this point, if samePart is true, then we're supposed to handle this event.
- // If samePart is not true then we should return errAEEventNotHandled and let
- // the event get redispatched to the correct part. If we are the root part, then
- // contextPart will be null simply because I don't think we need it given the
- // part reference that was passed in. Additionally, if you are planning on
- // keeping any of these SOM objects for any length of time you should Acquire them.
- if (samePart) {
- error = noErr;
- }
- else
- error = errAEEventNotHandled;
- CATCH_ALL
- error = ErrorCode();
- ENDTRY
-
- AEDisposeDesc(&realEvent);
- AEDisposeDesc(&realEvent);
- AEDisposeDesc(&obj);
- if (disposeToken)
- resolver->DisposeToken(ev, oslToken);
- else
- ODDeleteObject(oslToken);
- return error;
- } // HandleMeow
-
-
-